//
//  AllKindViewController.m
//  ToYourHeartNews
//
//  Created by XJing on 16/1/23.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥. All rights reserved.
//

#import "AllKindViewController.h"
#import "CellDetailViewController.h"
#import "BlackManager.h"
#import "SetBlack.h"
@interface AllKindViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *dataArr;
@end

@implementation AllKindViewController
- (void)dealloc
{
    [_allArr release];
    [_tableView release];
    [_dataArr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"分类";
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-newlisticon06"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)]autorelease];
    self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"allCell"];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    self.dataArr = [_allArr mutableCopy];
    [_dataArr removeObjectAtIndex:1];
    [_dataArr removeObjectAtIndex:3];
}
//点击进入详情
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //详情的连接
    NSString *str = [_dataArr[indexPath.row] objectForKey:@"api_url"];
    NSString *titleStr = [_dataArr[indexPath.row] objectForKey:@"title"];
     CellDetailViewController *cellVC = [[CellDetailViewController alloc]init];
    cellVC.str = str;
    cellVC.titleStr = titleStr;
    [self.navigationController pushViewController:cellVC animated:YES];
}
//返回按钮方法
-(void)backAction
{
    [self dismissViewControllerAnimated:YES completion:^{
        //
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_dataArr.count == 0) {
        UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前无网络!请查看网络设置" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
        [alertView1 show];
        UILabel *notice = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width / 2, self.view.frame.size.height / 3)];
        notice.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 3);
        notice.text = @"当前网络不给力,口袋里也装不进东西😢";
        notice.numberOfLines = 0;
        notice.textAlignment = NSTextAlignmentCenter;
        [_tableView addSubview:notice];

    }
    return _dataArr.count;
}
//页面出现时更新页面
-(void)viewWillAppear:(BOOL)animated
{
    [_tableView reloadData];
}
-(void)setLightDayModel
{
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
     [SetBlack setBackgroundColorWithView:self.view];
}
-(void)setNightDayModel
{
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    [SetBlack setBackgroundColorWithView:_tableView];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"allCell" forIndexPath:indexPath];
    [SetBlack setCellColorWithCell:cell];
    [SetBlack setLableTitleColorWithArr:@[cell.textLabel]];
    cell.textLabel.text = [_dataArr[indexPath.row] objectForKey:@"title"];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
